//
//  AppDelegate.swift
//  新浪微博
//
//  Created by 季伯文 on 2017/6/28.
//  Copyright © 2017年 bowen. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        //创建一个窗口
        window = UIWindow(frame: UIScreen.main.bounds)
        //背景颜色
        window?.backgroundColor = UIColor.white
        //设置根控制器
//        window?.rootViewController = JBWMainViewController()
        setupRootViewController()
        //成为主窗口
        window?.makeKeyAndVisible()
        
        print(JBWOAuthViewModel.share.isLogin)
//        let oauthVC = JBWOAuthViewController()
//        let model = oauthVC.getUserAccountModel()
//        print("得到Model:",model)
        //注册通知更改控制器
        NotificationCenter.default.addObserver(self, selector: #selector(switchRootViewController), name: JBWSWITCHVIEWCONTROLLERNOTI, object: nil)
        
        return true
    }
    

    @objc private func switchRootViewController(noti:Notification){
        
        if let _ = noti.object {
            window?.rootViewController = JBWMainViewController()
        } else {
            window?.rootViewController = JBWWelcomeViewController()
        }
    }
    
    private func setupRootViewController() {
        if JBWOAuthViewModel.share.isLogin {
            window?.rootViewController = JBWWelcomeViewController()
        } else {
            window?.rootViewController = JBWMainViewController()
        }
            
        }
    
}

